/*********************************************************************************
Organization 					: 				Georgia Institute of Technology
  
Institute 						:				Cognitive Computing Group(CCL)
 
Authors							: 				Manish Mehta 
 												
Class							:				NotEnoughGoldBOFix
 
Function						: 				A class for holding a basic operator
												fix for situations when 
												not enough gold is available
****************************************************************************/
package behavioradaptation.fixes;


import planninglanguage.plans.MultiPlan;
import planninglanguage.plans.Plan;
import planninglanguage.plans.ResourceBOPlan;
import planninglanguage.plans.SequentialPlan;
import base.WargusGameState;
import behavioradaptation.reasoner.GameStateHelpers;

public class NotEnoughGoldBOFix {
	public static Plan fix(Plan tobefixed, WargusGameState gameState)
	{
		int i;
		int PeasantID = -1;
		String []bldgs = {"peasant","peon"};
		
		for(i=0,PeasantID=-1;i<2 && PeasantID==-1;i++) {
			if(GameStateHelpers.GetUnitIDofType(gameState,0,bldgs[i]).size() != 0) {
				PeasantID = GameStateHelpers.GetUnitIDofType(gameState,0,bldgs[i]).get(0);
			}
		}
		if (PeasantID == -1) return null;
		// The fix is to harvest more gold
		MultiPlan fixedPlan = new SequentialPlan();
		fixedPlan.add( new ResourceBOPlan(PeasantID,0,null,null,null));
		fixedPlan.add((Plan)tobefixed.clone());
		return fixedPlan;
		
		
	}
}
